import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_easyrefresh/src/header/refresh_indicator.dart';
import 'package:flutter_module/common/base/base_list.dart';
import 'package:flutter_module/common/base/base_page.dart';

/// Create by kyluzoi
/// Date: 2021-08-17
///
/// Description:

class IndicatorPage extends BaseStateFulWidget {
  @override
  BaseState<StatefulWidget> buildState() {
    return _IndicatorState();
  }
}

class _IndicatorState extends BaseState<IndicatorPage>
    with BasePage, ListBehavior {
  @override
  String get appBarTitle => "指示器";

  List<String> list = [];


  @override
  void initState() {
    super.initState();
    isLoading = true;
    Future.delayed(Duration(milliseconds: 2000)).then((value) {
      setState(() {
        isLoading = false;
      });
    });
    _addList();
  }

  @override
  Widget createView(BuildContext context) {
    return ListView.builder(
        itemCount: list.length,
        itemBuilder: (context, index) {
          return Container(
            margin: EdgeInsets.all(10),
            height: 30.rpx,
            child: Text("Content$index"),
          );
        });
  }

  _addList() {
    for (int i = 0; i < 20; i++) {
      list.add("Content$i");
    }
  }

  @override
  OnRefreshCallback get onRefresh => () async {
        Future.delayed(Duration(milliseconds: 2000)).then((value) {
          print("下拉刷新成功");
          esRefreshController.finishRefresh(success: true);
          list.clear();
          setState(() {
            _addList();
          });
        });
      };

  OnLoadCallback get onLoad => () async {
        Future.delayed(Duration(milliseconds: 2000)).then((value) {
          esRefreshController.finishLoad();
          setState(() {
            _addList();
          });
        });
      };
}
